- The general Selection Problem is to find the order statistic for any value of
- We can still get a asymptotic runtime of )!
Randomized-Select
- A divide and conquer algorithm modeled after quicksort.
- Unlike quicksort that works on both sides of the partition. Randomized-Select works on only one side of the partition.
- That is why Randomized-Select is assuming the elements are distinct.
- That is the expected runtime but the worst case runtime is
- It uses the procedure Randomized-Partition
- Randomized algorithms are called “Randomized” because a part of the algorithm relies on the output of a random-number generator.
Randomized-Select - returns the smallest element of the array , where
Pseudocode:
Python Code:
Visual from Intro to algorithms book: